﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DLL测试
{
    public static class MotionControl
    {
        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionOpen", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionOpen(int ID, string Addr, int nPort,ref byte isowned);


        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionClose", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionClose(int handle);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionMoveToPos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionMoveToPos(int handle, short iAxis, double fSetPos, double fSetVel, int bIsAbs);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionStop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionStop(int handle);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionSetRatio", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionSetRatio(int handle, float[] fRatio);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionGetPrior", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionGetPrior(int handle);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionBackZero", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int MotionBackZero(int handle, short iAxis);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionClearZero", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int ClearZero (int handle);


        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionGetPos", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetPosition(int handle, short iAxis,ref int     bIsAbs,ref double  fPosition);


        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionGetVel", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int GetSpeed(int handle, short iAxis, ref int bIsAbs, ref double fVelocity);

        [DllImport("MotorCtrl_II2.dll", EntryPoint = "MotionSetSineMove", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
        public static extern int SinRun(int handle, short iAxis, double fSetFreq, double fSetAmp, int iSetTime);

    }
}
